﻿#ifndef IRTSPREADMANAGER_H_H_
#define  IRTSPREADMANAGER_H_H_


#include "base/CriticalSection.h"
#include "base/SimpleThread.h"
#include "ffmpegsdl.h"
#include <string>
#include <list>


class PlayCallback
{
public:
    PlayCallback(void){};
    virtual ~PlayCallback(void){};

    virtual void OnReadErrorEvent(void * rtsp_this, std::string pull_url) = 0;
};


class IRtspReadManager : public base::SimpleThread
{
public:
    IRtspReadManager(PlayCallback* _play_back);
	~IRtspReadManager(); 

	int StartRtspInputUrl(std::string url);

	int StopRtspInput();



	int OpenOutput(std::string outUrl);

	int CloseOutput();

	//线程
	virtual void Run();

    inline std::string GetPullUrl()
    {
        return pull_str_url_;
    }

private:
	int write_video_frame(AVPacket *packet);

private:


	AVFormatContext *pFormatCtx;

	int video_stream_index;           // index of video stream

	//----aac

	//opuput
	AVFormatContext * outputContext;

	FILE * audio_fp;

	int64_t last_mux_dts;

	AVRational  out_video_mux_timebase;

    std::string pull_str_url_;
    std::string write_mp4_file_name;

    PlayCallback*   play_back;
};
#endif //IRTSPREADMANAGER_H_H_
